﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;

public partial class reg : System.Web.UI.Page
{
    public bool ok = false;
    public bool error = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Thoi trang-thoitrang";
        Form.Attributes.Add("onsubmit", "return CheckForm(this);");
        Form.Method = "post"; 
        
        if (IsPostBack)
        {
            if (a_UserService.Geta_UserByEmail(Request["email_dangnhap"]) != null)
            {
                InfoError.InnerHtml = "Đăng ký thất bại! Email này đã được người khác sử dụng.";
                error = true;
            }
            else
            {
                a_User usr = new a_User();
                usr.Firstname = Request["ten"];
                usr.Lastname = Request["ho"];
                usr.Login_Email = Request["email_dangnhap"];
                usr.Password = Request["matma"];
                usr.Gender = Request["gioitinh"];
                usr.UserTypeID = int.Parse( Request["loaithanhvien"]);
                usr.LastVisit = DateTime.Now;
                usr.DateOpen = DateTime.Now;
                try
                {
                    a_UserService.Createa_User(usr);
                    Page.Title = "Thoi trang-thoitrang successful";
                    ok = true;
                }
                catch (Exception ex)
                {
                    Page.Title = "Thoi trang-thoitrang failed";
                    InfoError.InnerHtml = ex.Message;
                }
            }
        }
    }
}
